﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;

namespace CentrifugalSealCalc
{
    public static class Global
    {
        public static List<Expeller> Expellers = new List<Expeller>();
        public static List<Impeller> ImpellersOpen = new List<Impeller>();
        public static List<Impeller> ImpellersClosed = new List<Impeller>();
        public static double SpecificGravity = 1.3;  // included 17/03/2012 malith
        public static double InletGPressure = 45;
        public static double H0 = 17.1;        // from the curve WPA86A01 at 600 rpm
        public static double Hbep = 14.3;      // from the curve WPA86A01 at 600 rpm
        public static double Qbep = 114.0;     // from the curve WPA86A01 at 600 rpm

        public static Expeller GetExpeller(string name)
        {
            return Expellers.FirstOrDefault(x => x.Name == name);
        }

        public static Impeller GetImpellerOpen(string name)
        {
            return ImpellersOpen.FirstOrDefault(x => x.Name == name);
        }

        public static Impeller GetImpellerClosed(string name)
        {
            return ImpellersClosed.FirstOrDefault(x => x.Name == name);
        }

        public static string GetDescription(this Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());
            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
            return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
        }

        public static string[] GetEnumDescriptions<T>()
        {
            List<string> descriptions = new List<string>();
            Type enumType = typeof(T);

            if (enumType.BaseType != typeof(Enum))
            {
                throw new ArgumentException("T must be of type System.Enum");
            }

            foreach (int value in Enum.GetValues(enumType))
            {
                descriptions.Add(((Enum)Enum.ToObject(enumType, value)).GetDescription());
            }

            return descriptions.ToArray();
        }
    }
}